package view;

import controller.Controller;
import model.DataSource;
import controller.ActionLis;
import controller.MouseLis;

import javax.swing.*;
import java.awt.*;

public class LoginJPanel extends JPanel {


    public JLabel titleLabel;
    public JLabel usernameLabel;
    public JTextField usernameField;
    public JLabel passwordLabel;
    public JPasswordField passwordField;
    /* public JButton loginButton;
     public JButton registerButton;*/
    public JTextField checkField;
    public JLabel checkLabel;
    public MouseLis loginMouseLis;
    private Controller controller;
    public JButton loginButton;
    public JButton registerButton;
    public ActionLis actionLis=new ActionLis();
    public String Code;


    public LoginJPanel(Controller controller) {
        this.controller=controller;
        /*//设置标题的标签,并且添加
        loginMouseLis = new MouseLis(controller);
        addMouseListener(loginMouseLis);*/


        setLayout(null);
        setPreferredSize(new Dimension(1200, 800));
        titleLabel = new JLabel("欢迎来到欢乐斗地主！！");
        titleLabel.setBounds(400, 130, 300, 60);
        titleLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 23));
        titleLabel.setForeground(Color.BLACK);
        add(titleLabel);

        //设置用户名输入提示标签，并且添加
        usernameLabel = new JLabel("用户名");
        usernameLabel.setBounds(350, 280, 100, 30);
        usernameLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 20));
        usernameLabel.setForeground(Color.BLACK);
        add(usernameLabel);
        //建造用户名的输入框,并且添加
        usernameField = new JTextField();
        usernameField.setBounds(430, 280, 150, 30);
        usernameField.addActionListener(actionLis);
        add(usernameField);

        //设置密码输入提示的标签，并且添加
        passwordLabel = new JLabel("密码");
        passwordLabel.setBounds(370, 330, 100, 30);
        passwordLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 20));
        passwordLabel.setForeground(Color.BLACK);
        add(passwordLabel);
        //设置密码输入框,并且添加
        passwordField = new JPasswordField();
        passwordField.setBounds(430, 330, 150, 30);
        passwordField.addActionListener(actionLis);
        add(passwordField);

        //设置一个登录的按钮,并且添加
         /*loginButton = new JButton("登录");
         loginButton.setBounds(380, 400, 100, 30);
         add(loginButton);*/
        //设置一个去注册的按钮,并且添加
      /*   registerButton = new JButton("去注册");
          registerButton.setBounds(520, 400, 100, 30);
          add(registerButton);*/
        //设置一个验证码输入框，并且添加
        checkField = new JTextField();
        checkField.setBounds(640, 330, 100, 30);
        add(checkField);


        //设置一个验证码输入的提示及在页面上显示验证码
        checkLabel = new JLabel("验证码");
        checkLabel.setBounds(660, 360, 100, 30);
        checkLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 20));
        checkLabel.setForeground(Color.BLACK);
        add(checkLabel);
        Code = actionLis.checkCount();
        checkLabel.setText(Code);



         loginButton = new JButton("登录");
         loginButton.setBounds(500, 420, 120, 50);
         add(loginButton);
        /*actionLis.checkCount();*/
        loginButton.setActionCommand("login");
        loginButton.addActionListener(actionLis);


        /*registerButton.addActionListener(actionLis);*/
        /*registerButton.setActionCommand("goRegister");*/




    }


    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
       /* Image backGroundImage = new ImageIcon("background and button/background.png").getImage();
        Image loginImage = new ImageIcon("background and button/login.png").getImage();
        Image registerImage = new ImageIcon("background and button/goregister.png").getImage();
        Image pressLoginImage = new ImageIcon("background and button/presslogin.png").getImage();
        Image pressRegisterImage = new ImageIcon("background and button/pressregister.png").getImage();*/
        g.drawImage(DataSource.backGroundImage, 0, 0, 1200, 800, null);
       /* g.drawImage(DataSource.loginImage, 400, 440, 120, 60, null);
        g.drawImage(DataSource.registerImage, 540, 440, 120, 60, null);*/

    }

}



